<template>
	<view>
		<u-sticky>
			<u-subsection :list="list" :current="current" @change="sectionChange"></u-subsection>
		</u-sticky>

		<view>
			<u-list v-if="current==0" style="height: 100vh;" @scrolltolower="scrolltolower1" :show-scrollbar='true'>
				<u-empty mode="list" :show-scrollbar='true' v-if='todolist.length==0'
					icon="https://project.gxrunxiang.com/cdn/list.png">
				</u-empty>
				<u-list-item v-for="(item, index) in todolist" :key="index">
					<u-cell v-if='item.ActionName!="结束"' :title="`名称：${item.DataName || ''}`" :label='"创建时间："+item.CreateTime' isLink
						@click="toOpenPage(item)">

					</u-cell>
					<u-cell v-else :title="`名称：${item.DataName || ''}`" :label='"审批已通过，通过时间："+item.CreateTime' isLink
						@click="end(item.Id)">
					
					</u-cell>
				</u-list-item>
				<u-loadmore :status="status" v-if='downlist.length!=0' />
			</u-list>


			<u-list v-if="current==1" style="height: 100vh;" @scrolltolower="scrolltolower2" :show-scrollbar='true'>
				<u-empty mode="list" v-if='downlist.length==0' icon="https://project.gxrunxiang.com/cdn/list.png">
				</u-empty>
				<!-- @scrolltolower="scrolltolower" -->
				<u-list-item v-for="(item, index) in downlist" :key="index">
					<u-cell :title="`名称：${item.DataName || ''}`" :label='"完成时间："+item.FinishTime' isLink
						@click="toOpenFinish(item)"><!-- openPage(item.FlowAction.Route+'?id='+item.OutId) -->
					</u-cell>
				</u-list-item>
				<u-loadmore :status="status" v-if='downlist.length!=0' />
			</u-list>

		</view>
<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		gettodolist,
		end
	} from '@/common/api.js'
	import {
		getprojlist,
		GetNextOption,
		GoNext,
		GetCurrentAct,
	} from '@/common/api.js'
	export default {
		data() {
			return {
				status: 'loadmore',
				status1: 'loadmore',
				list: ['待办', '已办'],
				// list: ['待办', '已办', '已完成'],
				// 或者如下，也可以配置keyName参数修改对象键名
				// list: [{name: '未付款'}, {name: '待评价'}, {name: '已付款'}],
				current: 0,
				querytype: "",
				todolist: [],
				downlist: [],
				finishlist: [],
				hasTodolist: false,
				flowid: '',
				currentPage1: 1,
				currentPage2: 1,
				totalPage1: "",
				totalPage2: "",
				total1: 0,
				total2: 0,
				pageSize: 20,
				alert1: {
					type: 'error',
					icon: false,
					title: '失败主题',
					message: "请登录pc网页端查看处理",
					iconUrl: 'https://project.gxrunxiang.com/cdn/error.png'
				},
			}
		},
		// computed: {
		// 	hasTodolist: function() {
		// 		console.log(this.todolist)
		// 		return this.todolist.length == 0

		// 	}
		// },
		onLoad(options) {
			this.querytype = options.querytype;
			this.flowid = options.flowid
		
		},
		onShow()
		{
			this.todolist = []
			this.downlist = []
			this.currentPage1 = 1
			this.currentPage2 = 1
			this.getlist1()
			this.getlist2()
		},
		methods: {
			showalert()
			{
				this.$refs.uToast.show(this.alert1)
			},
			scrolltolower1() {
				if(this.currentPage1 >= this.totalPage1) {
					this.status1 = 'nomore';
						return;
					} ;
				this.status1 = 'loading';//状态改为加载中
				this.currentPage1 = ++ this.currentPage1;//页面新增一页
				this.getlist1();//修改页数后，重新获取数据
			},
			scrolltolower2() {
				this.currentPage2++
				this.status = "loading"
				this.getlist2()
			},
			sectionChange(index) {
				this.current = index;

			},
			openPage(url) {

				uni.navigateTo({
					url: url.replace('/', '')
				})
			},
			end(id)
			{
				end(id).then(res=>{
					this.todolist = []
					this.downlist = []
					this.currentPage1 = 1
					this.currentPage2 = 1
					this.getlist1()
					this.getlist2()
				})
			},
			getlist1() {
				if(this.flowid == 'store'){
					var para1 = {
						Parameters: [{
							FieldName: "Status",
							ConditionalType: "Equal",
							FieldValue: "待办"
						}, {
							FieldName: "FlowId",
							ConditionalType: "In",
							FieldValue: "出库管理审批流程(分公司(本级)),出库管理审批流程(公司总部),出库管理审批流程(市县项目部),调拨审批,,入库管理审批流程(分公司(本级)),入库管理审批流程(公司本部),入库管理审批流程(市县项目部),调拨审批,退料管理审批流程(分公司),退料管理审批流程(公司总部),退料管理审批流程(市县项目部)"
						}],
						pageIndex: this.currentPage1,
						pageSize: 20,
						orderBys: ["CreateTime desc"]
					}
				}else{
					var para1 = {
						Parameters: [{
							FieldName: "Status",
							ConditionalType: "Equal",
							FieldValue: "待办"
						}, {
							FieldName: "FlowId",
							ConditionalType: "Equal",
							FieldValue: this.flowid
						}],
						pageIndex: this.currentPage1,
						pageSize: 20,
						orderBys: ["CreateTime desc"]
					}
				}
				gettodolist(para1).then(res => {
					this.todolist = [...this.todolist, ...res.data]
					// console.log(this.todolist)
					// this.todolist = res.data
					this.total1 = res.count
					this.totalPage1 = Math.ceil(this.total1 / 20)
					if (res.data.length < 20) {
						this.status = "nomore"
					}
				})

			},
			getlist2() {
				// if (this.status == "nomore")
				// 	return
				if(this.flowid == 'store'){
					var para2 = {
						Parameters: [{
							FieldName: "Status",
							ConditionalType: "Equal",
							FieldValue: "已办"
						}, {
							FieldName: "FlowId",
							ConditionalType: "In",
							FieldValue: "出库管理审批流程(分公司(本级)),出库管理审批流程(公司总部),出库管理审批流程(市县项目部),调拨审批,,入库管理审批流程(分公司(本级)),入库管理审批流程(公司本部),入库管理审批流程(市县项目部),调拨审批,退料管理审批流程(分公司),退料管理审批流程(公司总部),退料管理审批流程(市县项目部)"
						}],
						pageIndex: this.currentPage1,
						pageSize: 20,
						orderBys: ["CreateTime desc"]
					}
				}else{
						let para2 = {
							Parameters: [{
								FieldName: "Status",
								ConditionalType: "Equal",
								FieldValue: "已办"
							}, {
								FieldName: "FlowId",
								ConditionalType: "Equal",
								FieldValue: this.flowid
							}],
							pageIndex: this.currentPage2,
							pageSize: 20,
							orderBys: ["CreateTime desc"]
						}
					}
				gettodolist(para2).then(res => {
					this.downlist = [...this.downlist, ...res.data]
					// console.log(this.downlist)
					if (res.data.length < 20) {
						this.status = "nomore"
					}
					// this.hasTodolist = (this.downlist.length == 0)
				})
			},
			toOpenPage(item){
				if(item.FlowName == "车辆维修保养审批"){
					uni.navigateTo({
						url: 'Car/maintenancedetail?Id=' + item.OutId
					})
				}else if(this.flowid == "store"){
					uni.navigateTo({
						url: 'Store/storein?storeChangeId=' + item.OutId + '&flowId=' + item.FlowId
					})
				}else{
					this.openPage(item.FlowAction.Route+'?id='+item.OutId+'&flowid='+item.FlowId)
				}
			},
			toOpenFinish(item){
				if(item.FlowName == "车辆维修保养审批"){
					uni.navigateTo({
						url: 'Car/maintenancedetail?Id=' + item.OutId
					})
				}else if(this.flowid == "store"){
					uni.navigateTo({
						url: 'Store/storein?storeChangeId=' + item.OutId + '&flowId=' + item.FlowId
					})
				}else{
					this.openPage(item.FlowAction.Route+'?id='+item.OutId)
				}
				
			}
		}
	}
</script>

<style>

</style>
